<script>
_h=h= Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var sWidth = parseInt((window.innerWidth > 0) ? window.innerWidth : screen.width);
if(sWidth>750){sWidth=750;}
var _rate=(sWidth/750);
if(h<_rate*1333){
	h=_rate*1333;
}
var _mbgFlag=true;
var _mbg=document.getElementById("mbg"); 
$(function(){
	$('.container, .p1-bg').width(sWidth).height(h);
	$('.p-b').width(sWidth).height(_rate*1333);
    $('.p1-logo').width(_rate*338).css({"top":0, "left":0});
	$('.p1-m').width(_rate*95).height(_rate*93).css({"top":_rate*32, "left":_rate*636});
	$('.p1-t1').css({"top":_rate*406});
    $('.p1-b1').width(_rate*404).height(_rate*138).css({"top":_rate*1060, "left":_rate*172});
    var _tmpH=_rate*619;
    $(".rule-t1").height(_tmpH).css({"top":(h-_tmpH)/2});
    //$('.p2-t1').height(_rate*799).css({"top":_rate*234});
    $(".p2-t1, .p2-box").width(_rate*637).height(_rate*788);
    $(".p2-tu").width(_rate*639);



    $(".p2-t1").css({"top":_rate*234, "left":_rate*56});
    $(".p2-b1").width(_rate*292).height(_rate*108).css({"top":_rate*1033, "left":_rate*38});
    $(".p2-b2").width(_rate*296).height(_rate*108).css({"top":_rate*1033, "left":_rate*420});
    $(".p2-b3").width(_rate*362).height(_rate*139).css({"top":_rate*1155, "left":_rate*192});
    $(".p2-t2").width(_rate*417).height(_rate*313).css({"top":_rate*482, "left":_rate*168});
  
    $(".p3-t2").width(_rate*671).height(_rate*782).css({"top":_rate*290, "left":_rate*40});
    $(".p3-k").width(_rate*673).height(_rate*784);
    $(".p3-l1").css({"top":_rate*254});
    

    $(".p3-b1").width(_rate*343).height(_rate*125).css({"top":_rate*1154, "left":_rate*205});


	$(".p1").fadeIn();
	window.setTimeout(function(){
		$(".rule").fadeIn();
	}, 900);
	$(".p1-b1").bind('click', function(){
        $(".p1").fadeOut();
        $(".p2").fadeIn();
     }); 
	$(".rule-close").bind('click', function(){
        $(".rule").fadeOut();
     }); 
	function _popMsg(msg){
		$(".weui-msg").html(msg);
        $(".js_dialog").show();
	}
    $(".weui-btn").click(function(){
        $(".js_dialog").hide();
	});

	wx.config({
        appId: '<?php echo $signPackage["appId"];?>',
        timestamp: <?php echo $signPackage["timestamp"];?>,
        nonceStr: '<?php echo $signPackage["nonceStr"];?>',
        signature: '<?php echo $signPackage["signature"];?>',
        jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData', 'showMenuItems', 'hideMenuItems','chooseImage','previewImage','uploadImage']
    });
	var _title='铭家点心';
	var _desc='分享你的今日心情';
	var _link='http://mei94.com/mingjia/';
	var _imgUrl='http://mei94.com/mingjia/img/64.jpg';
    wx.ready(function () {
    	wx.updateAppMessageShareData({
    	    title: _title, 
    	    desc: _desc, 
    	    link: _link, 
    	    imgUrl: _imgUrl,success: function () {}
    	  });
    	 wx.updateTimelineShareData({
              title: _desc, 
              link: _link, 
              imgUrl: _imgUrl, success: function () {}});
    });
    _mbg.play();
   document.addEventListener("WeixinJSBridgeReady", function () {
   	_mbg.play();
   }, false);
    var _hasAddMove=false;
    $(".p2-b1").click(function(){
		 wx.chooseImage({
		  count: 1, // 默认9
		  sizeType: ['compressed'],
		  sourceType: ['album', 'camera'], 
		  success: function (res) {
		  var _localIds = res.localIds; 
		  window.setTimeout(function(){
             wx.uploadImage({
				  localId: _localIds.toString(), 
				  isShowProgressTips: 1, 
				  success: function (res) {
				    var serverId = res.serverId; // 返回图片的服务器端ID
				   $("#pinchRotateImg").show();
		               $.post("tu.php", {s:serverId}, function(data){
	 
		            	    $(".p2-tu").attr("src","http://mei94.com/mingjia/upload/"+data.f);
		            	    if(false == _hasAddMove){
		            	    	_hasAddMove=true;
                                 addMove();
		            	    }

		               }, "json");

				  }
				});
		  }, 400);
		  
		  }
		});
    });
 
    function addMove(){
		   var pressMoveImg = document.getElementById("p2Img");
		   Transform(pressMoveImg);
		   new AlloyFinger(pressMoveImg, {
		       pressMove:function(evt){
		           pressMoveImg.translateX += evt.deltaX*2;
		           pressMoveImg.translateY += evt.deltaY*2;
		           evt.preventDefault();
		       },
		   	rotate:function(evt){
		           pressMoveImg.rotateZ += evt.angle;
		       },
		       multipointStart: function () {
		           initScale = pressMoveImg.scaleX;
		       },
		       pinch: function (evt) {
		           pressMoveImg.scaleX = pressMoveImg.scaleY = initScale * evt.zoom;
		       },
		   });
		   
	   }

   $(".p2-b2").click(function(){
        $(".p2-t2").fadeIn();
    });
 
   $(".p2-b3").click(function(){
   	    var _xinqing=$(".p2-input").val();
   	    console.log(_xinqing);
   	    if('' == _xinqing){
   	    	 _popMsg('请填写您的心情')
   	    	return;
   	    }
   	    $(".p2-txt").html(_xinqing);
   	    $(".p2-t2").hide();
 
        new html2canvas(document.getElementById('p2Box'),{logging:false,background:'',width:$('#p2Box').width(),height:$('#p2Box').height()
           }).then(canvas => {
			let oImg = new Image();
			oImg.src = canvas.toDataURL();
			console.log(oImg);
			//$(".p3-tu").attr("src" , canvas.toDataURL())
			$(".p3-tu").attr("src" , canvas.toDataURL("image/png",1.0));
            $(".p2").fadeOut();
            $(".p3").fadeIn();

			setTimeout(function(){
				oImg=null;
                new html2canvas(document.getElementById('p3Box'),{background:'',width:$('#p3Box').width(),height:$('#p3Box').height()}).then(canvas => {
                    //oImg = new Image();
					//oImg.src = canvas.toDataURL("image/png",1.0);
					//
					$(".p3-press").attr("src" , canvas.toDataURL("image/png",1.0));
					$.post("he.php", {pic:canvas.toDataURL()}, function(data){ }, "json");
                });
			},500);
			setTimeout(function(){
                  $.post("api/?c=setxin", {xin:_xinqing}, function(data){ }, "json");
			},700);
        });


    });

   $(".p1-m").click(function(){
		if(true == _mbgFlag){
			_mbgFlag=false;
			_mbg.pause();
			$(".p1-m").removeClass("gorotate").attr("src","./img/m2.png");
	    }else{
	    	_mbgFlag=true;
	    	_mbg.play();
	    	$(".p1-m").addClass("gorotate").attr("src","./img/m.png");
		}
    });
 
});
</script>